Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • CloudElement
  • DeleteBlock
  • DeleteOperation
  • EditBlock
  • Hooks
  • ManageBlock
  • Model
  • Module
  • OrderOperation
  • SaveOperation
  • Vocabulary
 1 <?php
 2 
 3 /*
 4  * This file is part of the Icybee package.
 5  *
 6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
 7  *
 8  * For the full copyright and license information, please view the LICENSE
 9  * file that was distributed with this source code.
10  */
11 
12 namespace Icybee\Modules\Taxonomy\Vocabulary;
13 
14 class Model extends \ICanBoogie\ActiveRecord\Model
15 {
16     public function save(array $properties, $key=null, array $options=array())
17     {
18         if (isset($properties['vocabulary']) && empty($properties['vocabularyslug']))
19         {
20             $properties['vocabularyslug'] = \Icybee\slugize($properties['vocabulary']);
21         }
22 
23         if (isset($properties['vocabularyslug']))
24         {
25             $properties['vocabularyslug'] = \ICanBoogie\normalize($properties['vocabularyslug']);
26         }
27 
28         $key = parent::save($properties, $key, $options);
29 
30         if (!$key)
31         {
32             return $key;
33         }
34 
35         $scope = array();
36 
37         if (isset($properties['scope']))
38         {
39             $insert = $this->prepare('INSERT IGNORE INTO {self}__scopes (vid, constructor) VALUES(?, ?)');
40 
41             foreach ($properties['scope'] as $constructor => $ok)
42             {
43                 $ok = filter_var($ok, FILTER_VALIDATE_BOOLEAN);
44 
45                 if (!$ok)
46                 {
47                     continue;
48                 }
49 
50                 $scope[] = $constructor;
51                 $insert->execute(array($key, $constructor));
52             }
53         }
54 
55         if ($scope)
56         {
57             $scope = array_map(array($this, 'quote'), $scope);
58 
59             $this->execute('DELETE FROM {self}__scopes WHERE vid = ? AND constructor NOT IN(' . implode(',', $scope) . ')', array($key));
60         }
61 
62         return $key;
63     }
64 
65     public function delete($key)
66     {
67         $rc = parent::delete($key);
68 
69         if ($rc)
70         {
71             $this->execute('DELETE FROM {self}__scopes WHERE vid = ?', array($key));
72             $this->clearTerms($key);
73         }
74 
75         return $rc;
76     }
77 
78     protected function clearTerms($vid)
79     {
80         // TODO: use model delete() method instead, maybe put an event on 'taxonomy.vocabulary.delete'
81 
82         global $core;
83 
84         $model = $core->models['taxonomy.terms'];
85         $model->execute('DELETE FROM {self}__nodes WHERE (SELECT vid FROM {self} WHERE {self}__nodes.vtid = {self}.vtid) = ?', array($vid));
86         $model->execute('DELETE FROM {self} WHERE vid = ?', array($vid));
87     }
88 }
Autodoc API documentation generated by ApiGen 2.8.0