public static function UpdateStatusOfConsumables($userId)
 {
     /*Get the user's group*/
     $ugRows = Usergroup::model()->findAll('uid=:uid', array(':uid' => $userId));
     $grps = [];
     foreach ($ugRows as $ug) {
         $grps[] = $ug['gid'];
     }
     /*Get Blocked Item Table Ids*/
     $getRows = BlockeditemUser::model()->findAllByAttributes(array('uid' => $userId));
     $biU = [];
     foreach ($getRows as $row) {
         $biU[] = $row['blockitem_id'];
     }
     $getRows = BlockeditemGroup::model()->findAllByAttributes(array('gid' => $grps));
     $biG = [];
     foreach ($getRows as $row) {
         $biG[] = $row['blockitem_id'];
     }
     ////////////Blocked For All
     $getRows = Blockeditem::model()->findAllByAttributes(array('flag' => 0));
     $biA = [];
     foreach ($getRows as $row) {
         $biA[] = $row['id'];
     }
     $blockeditemtableIds = array_merge($biU, $biG);
     $blockeditemtableIds = array_unique(array_merge($blockeditemtableIds, $biA));
     $consumableItemIds = Blockeditem::model()->findAllByAttributes(array('id' => $blockeditemtableIds));
     $consIds = [];
     foreach ($consumableItemIds as $row) {
         $consIds[] = $row['item_id'];
     }
     $getConsumables = Consumable::model()->findAll();
     foreach ($getConsumables as $cons) {
         $model = Consumable::model()->findByPk($cons['id']);
         if (in_array($cons['id'], $consIds)) {
             $model->isBlockedForMe = 1;
         } else {
             $model->isBlockedForMe = 0;
         }
         $model->update();
     }
 }
 public function search2()
 {
     // Warning: Please modify the following code to remove attributes that
     // should not be searched.
     $ugRows = Usergroup::model()->findAll('uid=:uid', array(':uid' => Yii::app()->user->getState("user_id")));
     $grps = [];
     foreach ($ugRows as $ug) {
         $grps[] = $ug['gid'];
     }
     /*Get Blocked Item  Ids*/
     $getRows = Blockeditem::model()->findAllByAttributes(array('blocked_for' => Yii::app()->user->getState("user_id"), 'flag' => 'U', 'unblock_by' => NULL));
     $biU = [];
     foreach ($getRows as $row) {
         $biU[] = $row['item_id'];
     }
     $getRows = Blockeditem::model()->findAllByAttributes(array('blocked_for' => $grps, 'flag' => 'G', 'unblock_by' => NULL));
     $biG = [];
     foreach ($getRows as $row) {
         $biG[] = $row['item_id'];
     }
     ////////////Blocked For All
     $getRows = Blockeditem::model()->findAllByAttributes(array('flag' => 'A', 'unblock_by' => NULL));
     $biA = [];
     foreach ($getRows as $row) {
         $biA[] = $row['item_id'];
     }
     $blockeditemtableIds = array_merge($biU, $biG);
     $blockeditemtableIds = array_unique(array_merge($blockeditemtableIds, $biA));
     $criteria = new CDbCriteria();
     $criteria->compare('id', $this->id);
     $criteria->compare('commodity_id', $this->commodity_id);
     $criteria->compare('category_id', $this->category_id, true);
     $criteria->compare('link_to', $this->link_to);
     $criteria->compare('name', $this->name, true);
     $criteria->compare('location_id', $this->location_id);
     $criteria->compare('technical_incharge_id', $this->technical_incharge_id);
     $criteria->compare('size', $this->size);
     $criteria->compare('status_id', $this->status_id);
     $criteria->compare('monitor_type_id', $this->monitor_type_id);
     $criteria->compare('manufacturer_id', $this->manufacturer_id);
     $criteria->compare('serial_number', $this->serial_number);
     $criteria->compare('management_type_id', $this->management_type_id);
     $criteria->compare('comments', $this->comments, true);
     $criteria->compare('document', $this->document, true);
     $criteria->compare('documentFileName', $this->documentFileName, true);
     $criteria->compare('documentFileType', $this->documentFileType, true);
     $criteria->compare('image', $this->image, true);
     $criteria->compare('imageFileName', $this->imageFileName, true);
     $criteria->compare('imageFileType', $this->imageFileType, true);
     $criteria->compare('enable_financial', $this->enable_financial, true);
     $criteria->compare('available_on_loan', $this->available_on_loan, true);
     $criteria->compare('has_microphone', $this->has_microphone, true);
     $criteria->compare('has_speaker', $this->has_speaker, true);
     $criteria->compare('has_subD', $this->has_subD, true);
     $criteria->compare('has_BNC', $this->has_BNC, true);
     $criteria->compare('has_DVI', $this->has_DVI, true);
     $criteria->compare('has_pivot', $this->has_pivot, true);
     $criteria->compare('has_HDMI', $this->has_HDMI, true);
     $criteria->compare('has_displayport', $this->has_displayport, true);
     $criteria->compare('is_deleted', $this->is_deleted);
     $criteria->addCondition("is_deleted = 0");
     $criteria->addNotInCondition('id', $blockeditemtableIds);
     if (isset($_GET['category_id'])) {
         $a = $_GET['category_id'];
         $criteria->addCondition("category_id = '{$a}'");
     }
     return new CActiveDataProvider($this, array('criteria' => $criteria, 'pagination' => false));
 }
 public function actionGeneratePdf()
 {
     $this->layout = 'pdf';
     $model = new Blockeditem('search');
     if (isset($_GET['Blockeditem'])) {
         $model->attributes = $_GET['Blockeditem'];
     }
     // to execute the filters (if is the case)
     $dataProvider = $model->search();
     $dataProvider->pagination = false;
     $mPDF1 = Yii::app()->ePdf->mpdf();
     # You can easily override default constructor's params
     $mPDF1 = Yii::app()->ePdf->mpdf('', 'A5');
     # renderPartial (only 'view' of current controller)
     $mPDF1->WriteHTML($this->renderPartial('admin', array('model' => $model), true));
     # Outputs ready PDF
     $mPDF1->Output();
 }
 /**
  * Retrieves a list of models based on the current search/filter conditions.
  * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
  */
 public function search()
 {
     // Warning: Please modify the following code to remove attributes that
     // should not be searched.
     $ugRows = Usergroup::model()->findAll('uid=:uid', array(':uid' => Yii::app()->user->getState("user_id")));
     $grps = [];
     foreach ($ugRows as $ug) {
         $grps[] = $ug['gid'];
     }
     /*Get Blocked Item  Ids*/
     $getRows = Blockeditem::model()->findAllByAttributes(array('blocked_for' => Yii::app()->user->getState("user_id"), 'flag' => 'U', 'unblock_by' => NULL));
     $biU = [];
     foreach ($getRows as $row) {
         $biU[] = $row['item_id'];
     }
     $getRows = Blockeditem::model()->findAllByAttributes(array('blocked_for' => $grps, 'flag' => 'G', 'unblock_by' => NULL));
     $biG = [];
     foreach ($getRows as $row) {
         $biG[] = $row['item_id'];
     }
     ////////////Blocked For All
     $getRows = Blockeditem::model()->findAllByAttributes(array('flag' => 'A', 'unblock_by' => NULL));
     $biA = [];
     foreach ($getRows as $row) {
         $biA[] = $row['item_id'];
     }
     $blockeditemtableIds = array_merge($biU, $biG);
     $blockeditemtableIds = array_unique(array_merge($blockeditemtableIds, $biA));
     $criteria = new CDbCriteria();
     $criteria->compare('category_id', $this->category_id, true);
     $criteria->compare('name', $this->name, true);
     $criteria->compare('location_id', $this->location_id);
     $criteria->compare('technical_incharge_id', $this->technical_incharge_id);
     $criteria->compare('status_id', $this->status_id);
     $criteria->compare('manufacturer_id', $this->manufacturer_id);
     $criteria->compare('cartridge_type_id', $this->cartridge_type_id);
     $criteria->compare('management_type_id', $this->management_type_id);
     $criteria->compare('threshold', $this->threshold);
     $criteria->compare('link_to', $this->link_to);
     $criteria->compare('image', $this->image, true);
     $criteria->compare('imageFileName', $this->imageFileName, true);
     $criteria->compare('imageFileType', $this->imageFileType, true);
     $criteria->compare('document', $this->document, true);
     $criteria->compare('documentFileName', $this->documentFileName, true);
     $criteria->compare('documentFileType', $this->documentFileType, true);
     $criteria->compare('is_deleted', $this->is_deleted);
     $criteria->addCondition("is_deleted = 0");
     $criteria->addNotInCondition('id', $blockeditemtableIds);
     if (isset($_GET['printerId'])) {
         $printerId = $_GET['printerId'];
         $criteria->addCondition("link_to = {$printerId}");
     }
     if (isset($_GET['category_id'])) {
         $a = $_GET['category_id'];
         $criteria->addCondition("category_id = '{$a}'");
     }
     return new CActiveDataProvider($this, array('criteria' => $criteria, 'pagination' => array('pageSize' => Yii::app()->user->getState('pageSize', 3))));
 }