Project

General

Profile

Feature #2681 » handbook_143_e41162d90023.patch

Laurent Opprecht, 21/02/2011 14:32

View differences:

php/blocks/handbook_connector.class.php
19 19
 *
20 20
 * @copyright (c) 2011 University of Geneva
21 21
 * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
22
 * @author lopprecht
22
 * @author laurent.opprecht
23 23
 * @package handbook.block
24 24
 * @author Hans De Bisschop
25 25
 */
26 26
class HandbookBlockConnector {
27 27

  
28 28
    /**
29
     * Returns a list of objects for the specified types.
29
     * Returns a list of objects that can be linked to a handbook block. That is the list of *published* handbooks.
30 30
     *
31
     * @param array $types
32 31
     * @return array
33 32
     */
34
    static function get_objects($types) {
35
        $result = array();
33
    function get_handbook_objects() {
34
         $result = array();
36 35

  
37
        $conditions = array();
38
        $conditions[] = new EqualityCondition(ContentObject :: PROPERTY_OWNER_ID, Session :: get_user_id());
36
        $condition = new AndCondition(array());
37
        $books = HandbookDataManager :: get_instance()->retrieve_published_handbooks($condition);
38
        while ($book = $books->next_result()) {
39
            $result[$book->get_id()] = $book->get_title();
40
        }
39 41

  
40
        $types_condition = array();
41
        foreach ($types as $type) {
42
            $types_condition[] = new EqualityCondition(ContentObject :: PROPERTY_TYPE, $type);
43
        }
44
        $conditions[] = new OrCondition($types_condition);
45
        $condition = new AndCondition($conditions);
46

  
47
        $rdm = RepositoryDataManager :: get_instance();
48
        $objects = $rdm->retrieve_content_objects($condition);
49

  
50
        if ($objects->size() == 0) {
42
        if (count($result) == 0) {
51 43
            $result[0] = Translation :: get('CreateObjectFirst');
52
        } else {
53
            while ($object = $objects->next_result()) {
54
                $result[$object->get_id()] = $object->get_title();
55
            }
56 44
        }
57 45

  
58 46
        return $result;
59 47
    }
60 48

  
61
    /**
62
     * Returns a list of objects that can be linked to a handbook block.
63
     *
64
     * @return array
65
     */
66
    function get_handbook_objects() {
67
        return self::get_objects(HandbookDisplay::get_supported_types());
68
    }
69

  
70 49

  
71 50
}
72 51

  
php/blocks/type/display.class.php
9 9
use common\libraries\Application;
10 10
use repository\content_object\handbook\Handbook;
11 11
use common\libraries\EqualityCondition;
12
use common\libraries\AndCondition;
12 13
use common\libraries\StringUtilities;
13 14
use repository\content_object\handbook_item\HandbookItem;
14 15
use repository\content_object\document\Document;
......
52 53
        parent::__construct($parent, $block_info, $configuration);
53 54
        $this->default_title = Translation::get('Handbook');
54 55
    }
55
    
56
    function is_visible()
57
    {
56

  
57
    function is_visible() {
58 58
        return true; //i.e.display on homepage when anonymous
59 59
    }
60 60

  
61
    function is_published() {
62
        return (bool) $this->retrieve_handbook_publication();
63
    }
64

  
61 65
    /**
62 66
     * Returns the html to display when the block is configured.
63 67
     *
64 68
     * @return string
65 69
     */
66 70
    function display_content() {
71
        if (!$this->is_published()) {
72
            return Translation :: get('PublishObjectFirst', null, HomeManager :: APPLICATION_NAME);
73
        }
74

  
67 75
        $content_object = $this->get_object();
68 76
        $display = ContentObjectDisplay :: factory($content_object);
69 77
        $DESCRIPTION = $display->get_description();
......
163 171
    }
164 172

  
165 173
    function get_view_handbook_url($handbook) {
174
        $publication = $this->retrieve_handbook_publication($handbook);
175
        if(empty($publication)){
176
            return '';
177
        }
166 178
        $params = array();
167 179
        $params[Application::PARAM_APPLICATION] = HandbookManager::APPLICATION_NAME;
168 180
        $params[HandbookManager :: PARAM_ACTION] = HandbookManager :: ACTION_VIEW_HANDBOOK;
169 181
        $params[HandbookManager :: PARAM_HANDBOOK_ID] = $handbook->get_id();
170
        $params[HandbookManager :: PARAM_HANDBOOK_PUBLICATION_ID] = $this->retrieve_handbook_publication($handbook);
182
        $params[HandbookManager :: PARAM_HANDBOOK_PUBLICATION_ID] = $publication->get_id();
171 183
        $params[HandbookManager :: PARAM_TOP_HANDBOOK_ID] = $params[HandbookManager :: PARAM_HANDBOOK_PUBLICATION_ID];
172 184
        return Redirect::get_link(HandbookManager::APPLICATION_NAME, $params);
173 185
    }
......
178 190
        $store = HandbookDataManager :: get_instance();
179 191
        $condition = new EqualityCondition(HandbookPublication :: PROPERTY_CONTENT_OBJECT_ID, $handbook_id);
180 192
        $publications = $store->retrieve_handbook_publications($condition);
181
        if (count($publications == 1)) {
182
            return $publications->next_result()->get_id();
193
        if ($publication = $publications->next_result()) {
194
            return $publication;
183 195
        } else {
184
            return 0;
196
            return null;
185 197
        }
186 198
    }
187 199

  
(1-1/2)