Example #1
0
 /**
  * 插入多个菜单
  * @param unknown $data
  */
 public function batchInsertMenu($data)
 {
     foreach ($data as $value) {
         $model = new self();
         $model->detachBehaviors();
         $model->attachBehavior("sluggable", ['class' => SluggableBehavior::className(), 'attribute' => 'originalName', 'ensureUnique' => true, "immutable" => true]);
         $model->originalName = $value["originalName"];
         $model->setAttributes($value);
         $model->save();
     }
     $this->rgt = (count($data) + 1) * 2;
     $this->save();
 }
 /**
  * Get the instance of the HelpDeskSetting according to the accountId
  * @param $accountId MongoId
  * @return Object<HelpDeskSetting>
  * @author Devin Jin
  **/
 public static function getInstance($accountId)
 {
     if (!self::$_instance instanceof self) {
         //In case that the account ID is string type, new helpdesk setting will be created (Bug #361)
         if ('string' === gettype($accountId)) {
             $accountId = new \MongoId($accountId);
         }
         $setting = self::findOne(['accountId' => $accountId]);
         if (empty($setting)) {
             $setting = new self();
             $setting->accountId = $accountId;
             if (!$setting->save()) {
                 throw new ServerErrorHttpException('Failed to create the object<HelpDeskSetting> for unknown reason.');
             }
         }
         $setting->attachBehavior('ChannelBehavior', new ChannelBehavior());
         $setting->syncHelpdeskChannels();
         self::$_instance = $setting;
     }
     return self::$_instance;
 }