/** * Prepares attributes before performing validation. */ protected function beforeValidate() { $scenario = $this->getScenario(); // avoid sql error 'incorrect date value' isset($_POST[__CLASS__]['invoiceDate']) && ($this->invoiceDate = MDate::formatToDb($this->invoiceDate, 'date')); isset($_POST[__CLASS__]['dueDate']) && ($this->dueDate = MDate::formatToDb($this->dueDate, 'date')); isset($_POST[__CLASS__]['startDate']) && ($this->startDate = MDate::formatToDb($this->startDate, 'date')); isset($_POST[__CLASS__]['endDate']) && ($this->endDate = MDate::formatToDb($this->endDate, 'date')); // parent does all common work return parent::beforeValidate(); }
/** * Prepares attributes before performing validation. */ protected function beforeValidate() { $scenario = $this->getScenario(); if (isset($_POST[__CLASS__]['billToCompany']) && $this->billToCompany !== self::BILL_TO_COMPANY && $this->billToCompany !== self::DO_NOT_BILL_TO_COMPANY) { // enum('0','1') null $this->billToCompany = null; } // avoid sql error 'incorrect date value' isset($_POST[__CLASS__]['expenseDate']) && ($this->expenseDate = MDate::formatToDb($this->expenseDate, 'date')); // parent does all common work return parent::beforeValidate(); }
/** * Prepares attributes before performing validation. */ protected function beforeValidate() { $scenario = $this->getScenario(); if (isset($_POST[__CLASS__]['contentMarkup']) && $this->contentMarkup !== self::TEXT) { // allow defined markups only $this->contentMarkup = self::CHECK; } if (isset($_POST[__CLASS__]['content'], $_POST[__CLASS__]['contentMarkup']) && empty($this->content)) { // empty text needs no markup $this->contentMarkup = null; } if (isset($_POST[__CLASS__]['paymentMethod']) && $this->paymentMethod !== self::CASH && $this->paymentMethod !== self::CHECK && $this->paymentMethod !== self::CREDIT_CARD && $this->paymentMethod !== self::PAYPAL && $this->paymentMethod !== self::WIRE) { // allow defined methods only $this->paymentMethod = self::CHECK; } // avoid sql error 'incorrect date value' isset($_POST[__CLASS__]['paymentDate']) && ($this->paymentDate = MDate::formatToDb($this->paymentDate, 'date')); // parent does all common work return parent::beforeValidate(); }
/** * @internal * * @return bool */ protected function _setValueForField(MApplicationControllerField $field, $value) { $object = null; try { if ($field->type() == MApplicationControllerField::StringType) { $object = S($value); } else { if ($field->type() == MApplicationControllerField::IntegerType) { $object = MNumber::parseInt($value); } else { if ($field->type() == MApplicationControllerField::FloatType) { $object = MNumber::parseFloat($value); } else { if ($field->type() == MApplicationControllerField::BooleanType) { $object = MNumber::parseBool($value); } else { if ($field->type() == MApplicationControllerField::DateType) { $object = MDate::parse($value); } else { if ($field->type() == MApplicationControllerField::BinaryType) { $object = MData::parseBase64String(S($value)); } else { if ($field->type() == MApplicationControllerField::ArrayType) { $object = new MMutableArray(); foreach ($value as $v) { $object->addObject(S($v)); } } else { if ($field->type() == MApplicationControllerField::DictionaryType) { $object = new MMutableDictionary(); foreach ($value as $k => $v) { $object->setObjectForKey(S($k), S($v)); } } } } } } } } } } catch (Exception $e) { return false; } if (!$this->fieldValues) { $this->fieldValues = new MMutableDictionary(); } if ($object) { $this->fieldValues->setObjectForKey($field, $object); return true; } else { return false; } }
/** * Migrate from old project management system. */ public function actionIndex() { // check rights if (!Yii::app()->user->checkAccess(User::ADMINISTRATOR)) { throw new CHttpException(403, Yii::t('Yii', 'You are not authorized to perform this action.')); } // models to migrate $migrate = array('User' => false, 'Company' => false, 'CompanyPayment' => false, 'Project' => false, 'Task' => false, 'Time' => true, 'Invoice' => false, 'Expense' => false); // start $message = ''; // we won't migrate unless form is submitted if (Yii::app()->request->isPostRequest) { // default criteria $findAllCriteria = new CDbCriteria(); $findAllCriteria->order = "`id` ASC"; if ($migrate['User']) { // user $mUsers = MUser::model()->findAll($findAllCriteria); if (is_array($mUsers)) { $i = $j = $c = 0; $accessType = array('customer' => 'client', 'consultant' => 'consultant', 'manager' => 'manager', 'admin' => 'administrator'); $accessLevel = array('customer' => 2, 'consultant' => 3, 'manager' => 4, 'admin' => 5); foreach ($mUsers as $oldModel) { if (($model = User::model()->findByPk($oldModel->id)) !== null) { $model->delete(); } // old model validation if (User::model()->findByAttributes(array('email' => $oldModel->email))) { $oldModel->email = rand(10, 99) . $oldModel->email; } $closeTime = strtotime($oldModel->close_date); $isActive = empty($oldModel->close_date) || $oldModel->close_date === '0000-00-00' || $closeTime === false; // new model $model = new User('migrate'); $model->username = $oldModel->email; $model->password = md5($oldModel->password); $model->email = $oldModel->email; $model->screenName = $oldModel->name; $model->accessType = isset($accessType[$oldModel->class]) ? $accessType[$oldModel->class] : 'member'; $model->accessLevel = isset($accessLevel[$oldModel->class]) ? $accessLevel[$oldModel->class] : 1; $model->isActive = $isActive ? '1' : '0'; $model->createTime = strtotime($oldModel->last); $model->id = $oldModel->id; if ($model->save()) { $i++; if (($userDetails = UserDetails::model()->findByPk($model->id)) !== null) { $userDetails->delete(); } $userDetails = new UserDetails('migrate'); $userDetails->emailConfirmationKey = md5(uniqid(rand(), true)); $userDetails->initials = $oldModel->inits; $userDetails->occupation = $oldModel->title; $userDetails->deactivationTime = $isActive ? null : $closeTime; $userDetails->administratorNote = '[from migration]'; $userDetails->userId = $model->id; $userDetails->save(); // relation between user and company if ($oldModel->customer_id >= 1) { $user2Company = new User2Company('migrate'); $user2Company->userId = $model->id; $user2Company->companyId = $oldModel->customer_id; $user2Company->position = 'owner'; //$oldModel->title if ($user2Company->save()) { $c++; } } } $j++; } $message .= $i . ' of ' . $j . ' users' . ($i === $c ? '' : ' with ' . $c . ' company (relations)') . ' have been migrated.<br/>'; } } if ($migrate['Company']) { // company $mCustomers = MCustomer::model()->findAll($findAllCriteria); if (is_array($mCustomers)) { $i = $j = $l = 0; foreach ($mCustomers as $oldModel) { if (($model = Company::model()->findByPk($oldModel->id)) !== null) { $model->delete(); } $closeTime = strtotime($oldModel->close_date); $isActive = empty($oldModel->close_date) || $oldModel->close_date === '0000-00-00' || $closeTime === false; $model = new Company('migrate'); $model->title = $oldModel->name; $model->titleAbbr = $oldModel->inits; $model->contactName = $oldModel->contact; $model->contactEmail = $oldModel->contact_email; $model->content = '[from migration]'; $model->contentMarkup = 'text'; $model->invoiceDueDay = $oldModel->terms_days; $model->isActive = $isActive ? '1' : '0'; $model->deactivationTime = $isActive ? null : $closeTime; $model->createTime = strtotime($oldModel->last); $model->id = $oldModel->id; if ($model->save()) { $i++; // associated location $location = new Location('migrate'); $location->address1 = $oldModel->addr; $location->address2 = $oldModel->addr2; $location->city = $oldModel->city; $location->state = $oldModel->state; $location->zipcode = $oldModel->zip; $location->content = '[from migration]'; $location->contentMarkup = 'text'; $location->createTime = strtotime($oldModel->last); if ($location->save()) { // relation between company and location $location2Record = new Location2Record('migrate'); $location2Record->locationId = $location->id; $location2Record->record = get_class($model); $location2Record->recordId = $model->id; if ($location2Record->save()) { $l++; } } } $j++; } $message .= $i . ' of ' . $j . ' companies' . ($i === $l ? '' : ' with ' . $l . ' locations') . ' have been migrated.<br/>'; } } if ($migrate['CompanyPayment']) { // company payment $mCustomerPayments = MCustomerPayment::model()->findAll($findAllCriteria); if (is_array($mCustomerPayments)) { $i = $j = 0; $paymentMethod = array('cash' => 'cash', 'check' => 'check', 'credit card' => 'creditCard'); foreach ($mCustomerPayments as $oldModel) { if (($model = CompanyPayment::model()->findByPk($oldModel->id)) !== null) { $model->delete(); } $model = new CompanyPayment('migrate'); $model->companyId = $oldModel->id; $model->paymentDate = MDate::formatToDb($oldModel->payment_date, 'date'); $model->amount = $oldModel->amount; $model->paymentMethod = $paymentMethod[$oldModel->payment_method]; $model->paymentNumber = $oldModel->payment_number; $model->content = $oldModel->note . "\n" . '[from migration]'; $model->contentMarkup = 'text'; $model->id = $oldModel->id; if ($model->save()) { $i++; } $j++; } $message .= $i . ' of ' . $j . ' company payments have been migrated.<br/>'; } } if ($migrate['Project']) { // project $mProjects = MProject::model()->findAll($findAllCriteria); if (is_array($mProjects)) { $i = $j = $c = $u = 0; foreach ($mProjects as $oldModel) { if (($model = Project::model()->findByPk($oldModel->id)) !== null) { $model->delete(); } $openDateNotSet = empty($oldModel->open_date) || $oldModel->open_date === '0000-00-00' || strtotime($oldModel->open_date) === false; $closeDateNotSet = empty($oldModel->close_date) || $oldModel->close_date === '0000-00-00' || strtotime($oldModel->close_date) === false; $model = new Project('migrate'); $model->title = $oldModel->name; $model->content = $oldModel->description . "\n" . '[from migration]'; $model->contentMarkup = 'text'; $model->hourlyRate = $oldModel->rate; $model->openDate = $openDateNotSet ? null : MDate::formatToDb($oldModel->open_date, 'date'); $model->closeDate = $closeDateNotSet ? null : MDate::formatToDb($oldModel->close_date, 'date'); $model->createTime = strtotime($oldModel->last); $model->id = $oldModel->id; if ($model->save()) { $i++; // relation between project and company if ($oldModel->customer_id >= 1) { $company2Project = new Company2Project('migrate'); $company2Project->companyId = $oldModel->customer_id; $company2Project->projectId = $model->id; if ($company2Project->save()) { $c++; } } // relation between project and manager if ($oldModel->manager_id >= 1) { $user2Project = new User2Project('migrate'); $user2Project->userId = $oldModel->manager_id; $user2Project->projectId = $model->id; $user2Project->role = 'manager'; if ($user2Project->save()) { $u++; } } } $j++; } $message .= $i . ' of ' . $j . ' projects' . ($i === $c ? '' : ' with ' . $c . ' company (relations)') . ($i === $u ? '' : ' with ' . $u . ' manager (relations)') . ' have been migrated.<br/>'; } } if ($migrate['Task']) { // task $mTasks = MTask::model()->findAll($findAllCriteria); if (is_array($mTasks)) { $i = $j = $u = $m = 0; $priority = array('A' => 2, 'B' => 3, 'C' => 4, '' => 3); $status = array('' => 'completed', 'Open' => 'completed', '0' => 'notStarted', 'New' => 'notStarted', 'Done' => 'completed', 'In Progress' => 'inProgress', 'Ready to Test' => 'readyToTest'); foreach ($mTasks as $oldModel) { if (($model = Task::model()->findByPk($oldModel->id)) !== null) { $model->delete(); } $hourlyRate = null; if ($oldModel->project_id >= 1 && ($project = Project::model()->findByPk($oldModel->project_id)) !== null) { $hourlyRate = $project->hourlyRate; } $dueDateNotSet = empty($oldModel->due_date) || $oldModel->due_date === '0000-00-00' || strtotime($oldModel->due_date) === false; $openDateNotSet = empty($oldModel->open_date) || $oldModel->open_date === '0000-00-00' || strtotime($oldModel->open_date) === false; $closeDateNotSet = empty($oldModel->close_date) || $oldModel->close_date === '0000-00-00' || strtotime($oldModel->close_date) === false; $model = new Task('migrate'); $model->title = $oldModel->name; $model->content = $oldModel->description . "\n" . '[from migration]'; $model->contentMarkup = 'text'; $model->companyId = $oldModel->customer_id; $model->projectId = $oldModel->project_id; $model->estimateMinute = (int) $oldModel->hours_estimate * 60; $model->dueDate = $dueDateNotSet ? null : MDate::formatToDb($oldModel->due_date, 'date'); $model->priority = $priority[$oldModel->priority]; $model->openDate = $openDateNotSet ? null : MDate::formatToDb($oldModel->open_date, 'date'); $model->closeDate = $closeDateNotSet ? null : MDate::formatToDb($oldModel->close_date, 'date'); $model->status = $status[$oldModel->task_status]; $model->report = $oldModel->work_report; $model->reportMarkup = 'text'; $model->hourlyRate = $hourlyRate; $model->isConfirmed = '1'; $model->confirmationTime = strtotime($oldModel->last); $model->createTime = strtotime($oldModel->last); $model->id = $oldModel->id; if ($model->save()) { $i++; // relation between task and consultant if ($oldModel->leader_id >= 1) { $user2Task = new User2Task('migrate'); $user2Task->userId = $oldModel->leader_id; $user2Task->taskId = $model->id; $user2Task->role = User2Task::CONSULTANT; if ($user2Task->save()) { $u++; } } // relation between task and manager if ($model->projectId >= 1) { $criteria = new CDbCriteria(); $criteria->order = "`" . User2Project::model()->tableName() . "`.`userPriority` ASC"; $criteria->order .= ",`" . User2Project::model()->tableName() . "`.`id` ASC"; if (($user2Project = User2Project::model()->findByAttributes(array('projectId' => $model->projectId, 'role' => 'manager'), $criteria)) !== null) { $user2Task = new User2Task('migrate'); $user2Task->userId = $user2Project->userId; $user2Task->taskId = $model->id; $user2Task->role = 'manager'; if ($user2Task->save()) { $m++; } } } } $j++; } $message .= $i . ' of ' . $j . ' tasks' . ($i === $u ? '' : ' with ' . $u . ' consultant (relations)') . ($i === $m ? '' : ' with ' . $m . ' manager (relations)') . ' have been migrated.<br/>'; } } if ($migrate['Time']) { // time $mTime = MTime::model()->findAll($findAllCriteria); if (is_array($mTime)) { $i = $j = $t = 0; foreach ($mTime as $oldModel) { if (($model = Time::model()->findByPk($oldModel->id)) !== null) { $model->delete(); } $taskId = $oldModel->task_id; if (empty($taskId) && $oldModel->project_id >= 1) { $criteria = new CDbCriteria(); $criteria->order = "`" . Task::model()->tableName() . "`.`id` ASC"; if (($task = Task::model()->findByAttributes(array('projectId' => $oldModel->project_id), $criteria)) !== null) { $taskId = $task->id; } else { // auto-generate a task $companyId = 0; $criteria = new CDbCriteria(); $criteria->order = "`" . Company2Project::model()->tableName() . "`.`companyPriority` ASC"; $criteria->order .= ", `" . Company2Project::model()->tableName() . "`.`id` ASC"; if (($company2Project = Company2Project::model()->findByAttributes(array('projectId' => $oldModel->project_id), $criteria)) !== null) { $companyId = $company2Project->companyId; } $hourlyRate = null; if (($project = Project::model()->findByPk($oldModel->project_id)) !== null) { $hourlyRate = $project->hourlyRate; } $task = new Task('migrate'); $task->projectId = $oldModel->project_id; $task->companyId = $companyId; $task->title = '[Auto Generated]'; $task->status = 'completed'; $task->dueDate = MDate::formatToDb($project === null ? 1234567890 : $project->createTime, 'date'); $task->openDate = MDate::formatToDb($project === null ? 1234567890 : $project->createTime, 'date'); $task->closeDate = MDate::formatToDb($project === null ? 1234567890 : $project->createTime, 'date'); $task->hourlyRate = $hourlyRate; $task->isConfirmed = 1; $task->confirmationTime = $project === null ? 1234567890 : $project->createTime; if ($task->save()) { $t++; $taskId = $task->id; // assigned consultant if ($oldModel->user_id >= 1) { $consultant2Task = new User2Task('migrate'); $consultant2Task->userId = $oldModel->user_id; $consultant2Task->taskId = $task->id; $consultant2Task->role = User2Task::CONSULTANT; $consultant2Task->save(); } // assigned manager $criteria = new CDbCriteria(); $criteria->order = "`" . User2Project::model()->tableName() . "`.`userPriority` ASC"; $criteria->order .= ", `" . User2Project::model()->tableName() . "`.`id` ASC"; if (($user2Project = User2Project::model()->findByAttributes(array('projectId' => $oldModel->project_id, 'role' => 'manager'), $criteria)) !== null) { $manager2Task = new User2Task('migrate'); $manager2Task->userId = $user2Project->userId; $manager2Task->taskId = $task->id; $manager2Task->role = User2Task::MANAGER; $manager2Task->save(); } } } } $managerId = null; if (!empty($taskId)) { $criteria = new CDbCriteria(); $criteria->order = "`" . User2Task::model()->tableName() . "`.`userPriority` ASC"; $criteria->order .= ",`" . User2Task::model()->tableName() . "`.`id` ASC"; if (($user2Task = User2Task::model()->findByAttributes(array('taskId' => $taskId, 'role' => 'manager'), $criteria)) !== null) { $managerId = $user2Task->userId; } } $timeDateNotSet = empty($oldModel->time_date) || $oldModel->time_date === '0000-00-00' || strtotime($oldModel->time_date) === false; $model = new Time('migrate'); $model->consultantId = $oldModel->user_id; $model->taskId = $taskId; $model->spentMinute = (int) $oldModel->hours_spent * 60; $model->timeDate = $timeDateNotSet ? null : MDate::formatToDb($oldModel->time_date, 'date'); $model->title = $oldModel->note; $model->content = $oldModel->details . "\n" . '[from migration]'; $model->contentMarkup = 'text'; $model->managerId = $managerId; $model->billedMinute = (int) $oldModel->hours_billed * 60; $model->invoiceId = $oldModel->invoice_id; $model->invoiceAmount = $oldModel->invoice_amount; $model->isConfirmed = '1'; $model->confirmationTime = strtotime($oldModel->last); $model->createTime = strtotime($oldModel->last); $model->id = $oldModel->id; if ($model->save()) { $i++; } $j++; } $message .= $i . ' of ' . $j . ' time records' . ($i === $t ? '' : ' with ' . $t . ' tasks') . ' have been migrated.<br/>'; } } if ($migrate['Invoice']) { // invoice $mInvoices = MInvoice::model()->findAll($findAllCriteria); if (is_array($mInvoices)) { $i = $j = 0; foreach ($mInvoices as $oldModel) { if (($model = Invoice::model()->findByPk($oldModel->id)) !== null) { $model->delete(); } $invoiceDateNotSet = empty($oldModel->invoice_date) || $oldModel->invoice_date === '0000-00-00' || strtotime($oldModel->invoice_date) === false; $startDateNotSet = empty($oldModel->start_date) || $oldModel->start_date === '0000-00-00' || strtotime($oldModel->start_date) === false; $endDateNotSet = empty($oldModel->end_date) || $oldModel->end_date === '0000-00-00' || strtotime($oldModel->end_date) === false; $dueDateNotSet = empty($oldModel->due_date) || $oldModel->due_date === '0000-00-00' || strtotime($oldModel->due_date) === false; $model = new Invoice('migrate'); $model->invoiceDate = $invoiceDateNotSet ? null : MDate::formatToDb($oldModel->invoice_date, 'date'); $model->companyId = $oldModel->customer_id; $model->billedMinute = (int) $oldModel->hours_billed * 60; $model->amountTotal = number_format($oldModel->total, 2, '.', ''); $model->startDate = $startDateNotSet ? null : MDate::formatToDb($oldModel->start_date, 'date'); $model->endDate = $endDateNotSet ? null : MDate::formatToDb($oldModel->end_date, 'date'); $model->dueDate = $dueDateNotSet ? null : MDate::formatToDb($oldModel->due_date, 'date'); $model->amountTime = number_format($oldModel->total, 2, '.', ''); $model->amountExpense = 0; $model->content = '[from migration]'; $model->contentMarkup = 'text'; $model->createTime = $invoiceDateNotSet ? null : strtotime($oldModel->invoice_date); $model->id = $oldModel->id; if ($model->save()) { $i++; } $j++; } $message .= $i . ' of ' . $j . ' invoices have been migrated.<br/>'; } } if ($migrate['Expense']) { // expense $mExpenses = MExpense::model()->findAll($findAllCriteria); if (is_array($mExpenses)) { $i = $j = 0; $billToCompany = array('Yes' => '1', 'No' => '0'); foreach ($mExpenses as $oldModel) { if (($model = Expense::model()->findByPk($oldModel->id)) !== null) { $model->delete(); } $expenseDateNotSet = empty($oldModel->expense_date) || $oldModel->expense_date === '0000-00-00' || strtotime($oldModel->expense_date) === false; $model = new Expense('migrate'); $model->managerId = $oldModel->user_id; $model->companyId = $oldModel->customer_id; $model->projectId = $oldModel->project_id; $model->invoiceId = $oldModel->invoice_id; $model->expenseDate = $expenseDateNotSet ? null : MDate::formatToDb($oldModel->expense_date, 'date'); $model->amount = $oldModel->amount; $model->billToCompany = $billToCompany[$oldModel->bill_to_customer]; $model->content = $oldModel->note . "\n" . '[from migration]'; $model->contentMarkup = 'text'; $model->createTime = strtotime($oldModel->last); $model->id = $oldModel->id; if ($model->save()) { $i++; } $j++; } $message .= $i . ' of ' . $j . ' expenses have been migrated.<br/>'; } } // last message line $message .= 'done'; } $this->render($this->action->id, array('message' => $message)); }
/** * Print out array of models for the jqGrid rows. */ public function actionGridData() { if (!Yii::app()->request->isPostRequest) { throw new CHttpException(400, Yii::t('http', 'Invalid request. Please do not repeat this request again.')); exit; } // specify request details $jqGrid = $this->processJqGridRequest(); // specify filter parameters $company = isset($_GET['company']) ? $_GET['company'] : null; if ($company !== 'all' && !ctype_digit($company)) { $company = 'all'; } $priority = isset($_GET['priority']) ? $_GET['priority'] : null; if ($priority !== 'all' && $priority !== (string) Project::PRIORITY_HIGHEST && $priority !== (string) Project::PRIORITY_HIGH && $priority !== (string) Project::PRIORITY_MEDIUM && $priority !== (string) Project::PRIORITY_LOW && $priority !== (string) Project::PRIORITY_LOWEST) { $priority = 'all'; } $state = isset($_GET['state']) ? $_GET['state'] : null; if ($state !== 'all' && $state !== 'closed' && $state !== 'open') { $state = 'all'; } // criteria $criteria = new CDbCriteria(); $criteria->group = "`t`.`id`"; // required by together() $criteria->select = "`t`.closeDate, `t`.hourlyRate, `t`.openDate, `t`.priority, `t`.title"; //$criteria->select="`t`.`closeDate`, `t`.`hourlyRate`, `t`.`openDate`, `t`.`priority`, `t`.`title`"; // uncomment in yii-1.1.2 if ($jqGrid['searchField'] !== null && $jqGrid['searchString'] !== null && $jqGrid['searchOper'] !== null) { $field = array('closeDate' => "`t`.`closeDate`", 'hourlyRate' => "`t`.`hourlyRate`", 'openDate' => "`t`.`openDate`", 'priority' => "`t`.`priority`", 'title' => "`t`.`title`", 'company' => "`Project_Company`.`title`"); $operation = $this->getJqGridOperationArray(); $keywordFormula = $this->getJqGridKeywordFormulaArray(); if (isset($field[$jqGrid['searchField']]) && isset($operation[$jqGrid['searchOper']])) { $criteria->condition = '(' . $field[$jqGrid['searchField']] . ' ' . $operation[$jqGrid['searchOper']] . ' :keyword)'; $criteria->params = array(':keyword' => str_replace('keyword', $jqGrid['searchString'], $keywordFormula[$jqGrid['searchOper']])); // search by special field types if ($jqGrid['searchField'] === 'createTime' && ($keyword = strtotime($jqGrid['searchString'])) !== false) { $criteria->params = array(':keyword' => str_replace('keyword', $keyword, $keywordFormula[$jqGrid['searchOper']])); if (date('H:i:s', $keyword) === '00:00:00') { // visitor is looking for a precision by day, not by second $criteria->condition = '(TO_DAYS(FROM_UNIXTIME(' . $field[$jqGrid['searchField']] . ',"%Y-%m-%d")) ' . $operation[$jqGrid['searchOper']] . ' TO_DAYS(FROM_UNIXTIME(:keyword,"%Y-%m-%d")))'; } } } } if ($company !== 'all') { $criteria->addCondition("`Project_Company`.`id`=:companyId"); $criteria->params[':companyId'] = $company; } if ($priority === (string) Project::PRIORITY_HIGHEST) { $criteria->addCondition("`t`.`priority`=:priorityHighest"); $criteria->params[':priorityHighest'] = Project::PRIORITY_HIGHEST; } else { if ($priority === (string) Project::PRIORITY_HIGH) { $criteria->addCondition("`t`.`priority`=:priorityHigh"); $criteria->params[':priorityHigh'] = Project::PRIORITY_HIGH; } else { if ($priority === (string) Project::PRIORITY_MEDIUM) { $criteria->addCondition("`t`.`priority`=:priorityMedium"); $criteria->params[':priorityMedium'] = Project::PRIORITY_MEDIUM; } else { if ($priority === (string) Project::PRIORITY_LOW) { $criteria->addCondition("`t`.`priority`=:priorityLow"); $criteria->params[':priorityLow'] = Project::PRIORITY_LOW; } else { if ($priority === (string) Project::PRIORITY_LOWEST) { $criteria->addCondition("`t`.`priority`=:priorityLowest"); $criteria->params[':priorityLowest'] = Project::PRIORITY_LOWEST; } } } } } if ($state === 'closed') { $criteria->addCondition("`t`.`closeDate` IS NOT NULL"); } else { if ($state === 'open') { $criteria->addCondition("(`t`.`closeDate` IS NULL OR TO_DAYS('" . MDate::formatToDb(time(), 'date') . "') < TO_DAYS(`t`.`closeDate`))"); } } if (User::isClient()) { $criteria->addCondition("`Company_User2Company`.`userId`=:clientId AND `Company_User2Company`.`position`=:clientPosition"); $criteria->params[':clientId'] = Yii::app()->user->id; $criteria->params[':clientPosition'] = Company::OWNER; } if (User::isConsultant()) { $criteria->addCondition("`Task_Consultant`.`id`=:consultantId"); $criteria->params[':consultantId'] = Yii::app()->user->id; } // pagination $with = array(); if (strpos($criteria->condition, 'Project_Company') !== false) { $with[] = 'allCompany'; } if (strpos($criteria->condition, 'Company_User2Company') !== false) { $with[] = 'allCompany.allUser2Company'; } if (strpos($criteria->condition, 'Task_Consultant') !== false) { $with[] = 'allTask.allConsultant'; } if (count($with) >= 1) { $pages = new CPagination(Project::model()->with($with)->count($criteria)); } else { $pages = new CPagination(Project::model()->count($criteria)); } $pages->pageSize = $jqGrid['pageSize'] !== null ? $jqGrid['pageSize'] : self::GRID_PAGE_SIZE; $pages->applyLimit($criteria); // sort $sort = new CSort('Project'); $sort->attributes = array('closeDate' => array('asc' => "`t`.`closeDate`", 'desc' => "`t`.`closeDate` desc", 'label' => Project::model()->getAttributeLabel('Closed')), 'hourlyRate' => array('asc' => "`t`.`hourlyRate`", 'desc' => "`t`.`hourlyRate` desc", 'label' => Project::model()->getAttributeLabel('Rate')), 'openDate' => array('asc' => "`t`.`openDate`", 'desc' => "`t`.`openDate` desc", 'label' => Project::model()->getAttributeLabel('Opened')), 'priority' => array('asc' => "`t`.`priority`", 'desc' => "`t`.`priority` desc", 'label' => Project::model()->getAttributeLabel('priority')), 'title' => array('asc' => "`t`.`title`", 'desc' => "`t`.`title` desc", 'label' => Project::model()->getAttributeLabel('title')), 'company' => array('asc' => "`Project_Company`.`title`", 'desc' => "`Project_Company`.`title` desc", 'label' => Company2Project::model()->getAttributeLabel('companyId'))); $sort->defaultOrder = "`t`.`closeDate` ASC, `t`.`priority` ASC, `t`.`createTime` DESC"; $sort->applyOrder($criteria); // find all $with = array('allCompany' => array('select' => 'title')); if (strpos($criteria->condition, 'Company_User2Company') !== false) { $with['allCompany.allUser2Company'] = array('select' => 'id'); } if (strpos($criteria->condition, 'Task_Consultant') !== false) { $with['allTask.allConsultant'] = array('select' => 'id'); } $together = strpos($criteria->condition, 'Project_Company') !== false || strpos($criteria->order, 'Project_Company') !== false || strpos($criteria->condition, 'Company_User2Company') !== false || strpos($criteria->condition, 'Task_Consultant') !== false; if ($together) { $models = Project::model()->with($with)->together()->findAll($criteria); } else { $models = Project::model()->with($with)->findAll($criteria); } // create resulting data array $data = array('page' => $pages->getCurrentPage() + 1, 'total' => $pages->getPageCount(), 'records' => $pages->getItemCount(), 'rows' => array()); foreach ($models as $model) { $data['rows'][] = array('id' => $model->id, 'cell' => array(isset($model->allCompany[0]->id) ? CHtml::link(CHtml::encode($model->allCompany[0]->title), array('company/show', 'id' => $model->allCompany[0]->id)) : '', CHtml::encode($model->title), CHtml::encode($model->hourlyRate), CHtml::encode($model->getAttributeView('priority')), CHtml::encode(MDate::format($model->openDate, 'medium', null)), CHtml::encode(MDate::format($model->closeDate, 'medium', null)), CHtml::link('<span class="ui-icon ui-icon-zoomin"></span>', array('show', 'id' => $model->id), array('class' => 'w3-ig w3-link-icon w3-border-1px-transparent w3-first ui-corner-all', 'title' => Yii::t('link', 'Show'))) . CHtml::link('<span class="ui-icon ui-icon-pencil"></span>', array('update', 'id' => $model->id), array('class' => 'w3-ig w3-link-icon w3-border-1px-transparent w3-last ui-corner-all', 'title' => Yii::t('link', 'Edit'))))); } $this->printJson($data); }
/** * Prepares attributes before performing validation. */ protected function beforeValidate() { $scenario = $this->getScenario(); if (isset($_POST[__CLASS__]['isConfirmed'])) { if ($this->isConfirmed !== self::IS_CONFIRMED && $this->isConfirmed !== self::IS_NOT_CONFIRMED) { // enum('0','1') null $this->isConfirmed = null; } if ($this->isConfirmed === self::IS_CONFIRMED && empty($this->confirmationTime)) { // set time on confirm $this->confirmationTime = time(); } else { if ($this->isConfirmed === self::IS_NOT_CONFIRMED && $this->confirmationTime !== null) { // unset time on unconfirm $this->confirmationTime = null; } } } // number of minutes = number of minutes + number of hours * 60 if ($this->spentH !== null || $this->spentM !== null) { $this->spentMinute = (int) ((double) $this->spentH * 60 + (int) $this->spentM); } if ($this->billedH !== null || $this->billedM !== null) { $this->billedMinute = (int) ((double) $this->billedH * 60 + (int) $this->billedM); } // avoid sql error 'out of range value adjusted for column' if ($this->spentMinute > 999999) { $this->spentMinute = 999999; } if ($this->billedMinute > 999999) { $this->billedMinute = 999999; } // avoid sql error 'incorrect date value' isset($_POST[__CLASS__]['timeDate']) && ($this->timeDate = MDate::formatToDb($this->timeDate, 'date')); // parent does all common work return parent::beforeValidate(); }
/** Define how days left to given date. date according to dateFormat parameter passed on inizialization * @access public * @param date $date The date in traditional format for calculating diff * @return int The amount of days between today and given date */ public function howTo($date) { $today = new MDate(Manager::getSysDate()); return $today->diff($date, '%a'); }
public function inputCalendar($control) { $this->page->addDojoRequire('manager/DateTextBox'); $control->addDojoProp('promptMessage', "Formato: DD/MM/AAAA"); $control->setDojoType('manager/DateTextBox'); if ($control->property->rangeDate) { $minDate = $control->property->rangeDate[0]; $maxDate = $control->property->rangeDate[1]; if ($minDate) { $date = new MDate($minDate); $min = $date->format('Y') . ',' . ($date->format('m') - 1) . ',' . $date->format('d'); $this->page->onload("manager.byId('{$control->id}').constraints.min = new Date({$min});"); } if ($maxDate) { $date = new MDate($maxDate); $max = $date->format('Y') . ',' . ($date->format('m') - 1) . ',' . $date->format('d'); $this->page->onload("manager.byId('{$control->id}').constraints.max = new Date({$max});"); } } return $this->inputfield($control); }
/** * Find all open projects. * @param array of additional conditions * @return array of Project objects */ public function findAllOpenRecords($conditions = array()) { $id = isset($conditions[0]) && ctype_digit($conditions[0]) && $conditions[0] >= 1 ? $conditions[0] : null; $criteria = new CDbCriteria(); $t = self::model()->tableName(); // close date is not set, or it is later than today $criteria->condition = "`{$t}`.`closeDate` IS NULL OR TO_DAYS('" . MDate::formatToDb(time(), 'date') . "') < TO_DAYS(`{$t}`.`closeDate`)"; if ($id) { $criteria->condition .= " OR `{$t}`.`id` = '{$id}'"; } return self::model()->findAll($criteria); }
/** * Time report. */ public function actionReport() { $criteria = new CDbCriteria(); $criteria->select = "`t`.billedMinute, `t`.spentMinute, `t`.timeDate, `t`.title"; //$criteria->select="`t`.`billedMinute`, `t`.`spentMinute`, `t`.`timeDate`, `t`.`title`"; // uncomment in yii-1.1.2 $criteria->condition = "TO_DAYS(`t`.`timeDate`) >= TO_DAYS('2009-09-09')"; $criteria->order = "`t`.`timeDate` ASC, `t`.`createTime` ASC"; $with = array('task' => array('select' => 'hourlyRate,title'), 'task.company' => array('select' => 'title'), 'task.project' => array('select' => 'title')); if (Yii::app()->user->checkAccess(User::CLIENT)) { $with['manager'] = array('select' => 'screenName'); } else { $with['consultant'] = array('select' => 'screenName'); } $models = Time::model()->with($with)->findAll($criteria); $data = array(); foreach ($models as $model) { $companyId = isset($model->task->company->id) ? $model->task->company->id : 0; if (!isset($data[$companyId]['company']) && isset($model->task->company->id)) { $data[$companyId]['company'] = $model->task->company; } $projectId = isset($model->task->project->id) ? $model->task->project->id : 0; if (!isset($data[$companyId]['allProject'][$projectId]['project']) && isset($model->task->project->id)) { $data[$companyId]['allProject'][$projectId]['project'] = $model->task->project; } $taskId = isset($model->task->id) ? $model->task->id : 0; if (!isset($data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['task']) && isset($model->task->id)) { $data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['task'] = $model->task; } $timeId = $model->id; if (Yii::app()->user->checkAccess(User::CLIENT) || Yii::app()->user->checkAccess(User::CONSULTANT)) { $member = isset($model->manager->id) ? $model->manager : null; } else { $member = isset($model->consultant->id) ? $model->consultant : null; } $data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['gridRows'][] = array(array('content' => $member !== null ? CHtml::link($member->screenName !== '' ? CHtml::encode($member->screenName) : $member->id, array('user/show', 'id' => $member->id)) : ''), array('align' => 'right', 'content' => CHtml::encode(MDate::format($model->timeDate, 'short', null)), 'title' => CHtml::encode(MDate::format($model->timeDate, 'full', null))), array('content' => CHtml::link($model->title !== '' ? CHtml::encode($model->title) : $model->id, array('time/show', 'id' => $model->id))), array('align' => 'right', 'content' => $model->getAttributeView('billedMinute'), 'title' => Yii::t('t', 'Hourly rate') . ': ' . (isset($model->task->id) ? (int) $model->task->hourlyRate : '?')), array('align' => 'right', 'content' => $model->getAttributeView('spentMinute'), 'title' => Yii::t('t', 'Hourly rate') . ': ' . (isset($model->task->id) ? (int) $model->task->hourlyRate : '?'))); if (!isset($data[$companyId]['total']['billedMinute'])) { $data[$companyId]['total']['billedMinute'] = 0; } if (!isset($data[$companyId]['total']['spentMinute'])) { $data[$companyId]['total']['spentMinute'] = 0; } if (!isset($data[$companyId]['total']['billedAmount'])) { $data[$companyId]['total']['billedAmount'] = 0; } if (!isset($data[$companyId]['total']['spentAmount'])) { $data[$companyId]['total']['spentAmount'] = 0; } if (!isset($data[$companyId]['allProject'][$projectId]['total']['billedMinute'])) { $data[$companyId]['allProject'][$projectId]['total']['billedMinute'] = 0; } if (!isset($data[$companyId]['allProject'][$projectId]['total']['spentMinute'])) { $data[$companyId]['allProject'][$projectId]['total']['spentMinute'] = 0; } if (!isset($data[$companyId]['allProject'][$projectId]['total']['billedAmount'])) { $data[$companyId]['allProject'][$projectId]['total']['billedAmount'] = 0; } if (!isset($data[$companyId]['allProject'][$projectId]['total']['spentAmount'])) { $data[$companyId]['allProject'][$projectId]['total']['spentAmount'] = 0; } if (!isset($data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['billedMinute'])) { $data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['billedMinute'] = 0; } if (!isset($data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['spentMinute'])) { $data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['spentMinute'] = 0; } if (!isset($data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['billedAmount'])) { $data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['billedAmount'] = 0; } if (!isset($data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['spentAmount'])) { $data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['spentAmount'] = 0; } $data[$companyId]['total']['billedMinute'] += $model->billedMinute; $data[$companyId]['total']['spentMinute'] += $model->spentMinute; $data[$companyId]['allProject'][$projectId]['total']['billedMinute'] += $model->billedMinute; $data[$companyId]['allProject'][$projectId]['total']['spentMinute'] += $model->spentMinute; $data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['billedMinute'] += $model->billedMinute; $data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['spentMinute'] += $model->spentMinute; if (isset($model->task->id)) { $data[$companyId]['total']['billedAmount'] += $model->billedMinute / 60 * (int) $model->task->hourlyRate; $data[$companyId]['total']['spentAmount'] += $model->spentMinute / 60 * (int) $model->task->hourlyRate; $data[$companyId]['allProject'][$projectId]['total']['billedAmount'] += $model->billedMinute / 60 * (int) $model->task->hourlyRate; $data[$companyId]['allProject'][$projectId]['total']['spentAmount'] += $model->spentMinute / 60 * (int) $model->task->hourlyRate; $data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['billedAmount'] += $model->billedMinute / 60 * (int) $model->task->hourlyRate; $data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['spentAmount'] += $model->spentMinute / 60 * (int) $model->task->hourlyRate; } } $this->render($this->action->id, array('data' => $data, 'models' => $models, 'cn', 'pn', 'tn')); }
/** * @return MManagedObject */ private function _parseObjectFromXML(SimpleXMLElement $xmlObject, callable $callback = null) { $entityName = S($xmlObject->getName()); $entity = $this->persistentStoreCoordinator()->model()->entityWithName($entityName); if ($entity) { $object = $this->newObjectForEntity($entity); if ($object) { foreach ($xmlObject->children() as $xmlAttribute) { $attribute = $entity->attributeWithName(S($xmlAttribute->getName())); if ($attribute instanceof MEntityDescriptionProperty) { if ($attribute->type() == MEntityDescriptionProperty::StringType) { $object->setObjectForAttribute($attribute, S((string) $xmlAttribute)); } else { if ($attribute->type() == MEntityDescriptionProperty::IntegerType) { $object->setObjectForAttribute($attribute, N((int) $xmlAttribute)); } else { if ($attribute->type() == MEntityDescriptionProperty::FloatType) { $object->setObjectForAttribute($attribute, N((double) $xmlAttribute)); } else { if ($attribute->type() == MEntityDescriptionProperty::BooleanType) { $object->setObjectForAttribute($attribute, N((bool) $xmlAttribute)); } else { if ($attribute->type() == MEntityDescriptionProperty::DateType) { $object->setObjectForAttribute($attribute, MDate::parse((string) $xmlAttribute)); } else { if ($attribute->type() == MEntityDescriptionProperty::BinaryType) { $object->setObjectForAttribute($attribute, MData::dataWithBytes((string) $xmlAttribute)); } else { throw new MInvalidDataTypeException(S("StringType|IntegerType|FloatType|BooleanType|DateType|BinaryType"), S($attribute->type())); } } } } } } } else { if ($attribute instanceof MEntityDescriptionRelationship) { foreach ($xmlAttribute->children() as $xmlRelationshipObject) { $object->addObjectToRelationship($attribute, $this->_parseObjectFromXML($xmlRelationshipObject)); } } else { throw new MManagedObjectException($object, Sf("Attribute type '%s' not supported", $attribute->className())); } } } if (!is_null($callback)) { $callback($object); } return $object; } else { throw new MManagedObjectException($object, S("Could not create object")); } } else { throw new MEntityNotFoundException($entityName); } }
/** * Print out array of models for the jqGrid rows. */ public function actionGridData() { if (!Yii::app()->request->isPostRequest) { throw new CHttpException(400, Yii::t('http', 'Invalid request. Please do not repeat this request again.')); exit; } // specify request details $jqGrid = $this->processJqGridRequest(); // specify filter parameters $company = isset($_GET['company']) ? $_GET['company'] : null; if ($company !== 'all' && !ctype_digit($company)) { $company = 'all'; } $project = isset($_GET['project']) ? $_GET['project'] : null; if ($project !== 'all' && !ctype_digit($project)) { $project = 'all'; } $billToCompany = isset($_GET['billToCompany']) ? $_GET['billToCompany'] : null; if ($billToCompany !== 'all' && $billToCompany !== (string) Expense::BILL_TO_COMPANY && $billToCompany !== (string) Expense::DO_NOT_BILL_TO_COMPANY) { $billToCompany = 'all'; } // criteria $criteria = new CDbCriteria(); $criteria->group = "`t`.`id`"; // required by together() $criteria->select = "`t`.amount, `t`.billToCompany, `t`.expenseDate"; //$criteria->select="`t`.`amount`, `t`.`billToCompany`, `t`.`expenseDate`"; // uncomment in yii-1.1.2 if ($jqGrid['searchField'] !== null && $jqGrid['searchString'] !== null && $jqGrid['searchOper'] !== null) { $field = array('amount' => "`t`.`amount`", 'billToCompany' => "`t`.`billToCompany`", 'expenseDate' => "`t`.`expenseDate`", 'company' => "`Expense_Company`.`title`", 'project' => "`Expense_Project`.`title`"); $operation = $this->getJqGridOperationArray(); $keywordFormula = $this->getJqGridKeywordFormulaArray(); if (isset($field[$jqGrid['searchField']]) && isset($operation[$jqGrid['searchOper']])) { $criteria->condition = '(' . $field[$jqGrid['searchField']] . ' ' . $operation[$jqGrid['searchOper']] . ' :keyword)'; $criteria->params = array(':keyword' => str_replace('keyword', $jqGrid['searchString'], $keywordFormula[$jqGrid['searchOper']])); // search by special field types if ($jqGrid['searchField'] === 'createTime' && ($keyword = strtotime($jqGrid['searchString'])) !== false) { $criteria->params = array(':keyword' => str_replace('keyword', $keyword, $keywordFormula[$jqGrid['searchOper']])); if (date('H:i:s', $keyword) === '00:00:00') { // visitor is looking for a precision by day, not by second $criteria->condition = '(TO_DAYS(FROM_UNIXTIME(' . $field[$jqGrid['searchField']] . ',"%Y-%m-%d")) ' . $operation[$jqGrid['searchOper']] . ' TO_DAYS(FROM_UNIXTIME(:keyword,"%Y-%m-%d")))'; } } } } if ($company !== 'all') { $criteria->addCondition("`Expense_Company`.`id`=:companyId"); $criteria->params[':companyId'] = $company; } if ($project !== 'all') { $criteria->addCondition("`Expense_Project`.`id`=:projectId"); $criteria->params[':projectId'] = $project; } if ($billToCompany === (string) Expense::BILL_TO_COMPANY) { $criteria->addCondition("`t`.`billToCompany`=:billToCompany"); $criteria->params[':billToCompany'] = Expense::BILL_TO_COMPANY; } else { if ($billToCompany === (string) Expense::DO_NOT_BILL_TO_COMPANY) { $criteria->addCondition("`t`.`billToCompany`=:doNotBillToCompany"); $criteria->params[':doNotBillToCompany'] = Expense::DO_NOT_BILL_TO_COMPANY; } } if (User::isClient()) { $criteria->addCondition("`Company_User2Company`.`userId`=:clientId AND `Company_User2Company`.`position`=:clientPosition"); $criteria->params[':clientId'] = Yii::app()->user->id; $criteria->params[':clientPosition'] = Company::OWNER; } // pagination $with = array(); if (strpos($criteria->condition, 'Expense_Company') !== false) { $with[] = 'company'; } if (strpos($criteria->condition, 'Expense_Project') !== false) { $with[] = 'project'; } if (strpos($criteria->condition, 'Company_User2Company') !== false) { $with[] = 'company.allUser2Company'; } if (count($with) >= 1) { $pages = new CPagination(Expense::model()->with($with)->count($criteria)); } else { $pages = new CPagination(Expense::model()->count($criteria)); } $pages->pageSize = $jqGrid['pageSize'] !== null ? $jqGrid['pageSize'] : self::GRID_PAGE_SIZE; $pages->applyLimit($criteria); //sort $sort = new CSort('Expense'); $sort->attributes = array('amount' => array('asc' => "`t`.`amount`", 'desc' => "`t`.`amount` desc", 'label' => Expense::model()->getAttributeLabel('amount')), 'billToCompany' => array('asc' => "`t`.`billToCompany`", 'desc' => "`t`.`billToCompany` desc", 'label' => Expense::model()->getAttributeLabel('Bill')), 'expenseDate' => array('asc' => "`t`.`expenseDate`", 'desc' => "`t`.`expenseDate` desc", 'label' => Expense::model()->getAttributeLabel('Date')), 'company' => array('asc' => "`Expense_Company`.`title`", 'desc' => "`Expense_Company`.`title` desc", 'label' => Expense::model()->getAttributeLabel('companyId')), 'project' => array('asc' => "`Expense_Project`.`title`", 'desc' => "`Expense_Project`.`title` desc", 'label' => Expense::model()->getAttributeLabel('projectId'))); $sort->defaultOrder = "`t`.`expenseDate` DESC, `t`.`id` DESC"; $sort->applyOrder($criteria); // find all $with = array('company' => array('select' => 'title'), 'project' => array('select' => 'title')); if (strpos($criteria->condition, 'Company_User2Company') !== false) { $with['company.allUser2Company'] = array('select' => 'id'); } $together = strpos($criteria->condition, 'Company_User2Company') !== false; if ($together) { $models = Expense::model()->with($with)->together()->findAll($criteria); } else { $models = Expense::model()->with($with)->findAll($criteria); } // create resulting data array $data = array('page' => $pages->getCurrentPage() + 1, 'total' => $pages->getPageCount(), 'records' => $pages->getItemCount(), 'rows' => array()); foreach ($models as $model) { $data['rows'][] = array('id' => $model->id, 'cell' => array(isset($model->company->id) ? CHtml::link(CHtml::encode($model->company->title), array('company/show', 'id' => $model->company->id)) : '', isset($model->project->id) ? CHtml::link(CHtml::encode($model->project->title), array('project/show', 'id' => $model->project->id)) : '', CHtml::encode(MDate::format($model->expenseDate, 'medium', null)), CHtml::encode($model->amount), CHtml::encode($model->getAttributeView('billToCompany', 'grid')), User::isManager() && empty($model->invoiceId) || User::isAdministrator() ? CHtml::link('<span class="ui-icon ui-icon-zoomin"></span>', array('show', 'id' => $model->id), array('class' => 'w3-ig w3-link-icon w3-border-1px-transparent w3-first ui-corner-all', 'title' => Yii::t('link', 'Show'))) . CHtml::link('<span class="ui-icon ui-icon-pencil"></span>', array('update', 'id' => $model->id), array('class' => 'w3-ig w3-link-icon w3-border-1px-transparent ui-corner-all', 'title' => Yii::t('link', 'Edit'))) . CHtml::link('<span class="ui-icon ui-icon-trash"></span>', array('delete', 'id' => $model->id), array('class' => 'w3-ig w3-link-icon w3-border-1px-transparent w3-last ui-corner-all', 'title' => Yii::t('link', 'Delete the record number {id}', array('{id}' => $model->id)))) : CHtml::link('<span class="ui-icon ui-icon-zoomin"></span>', array('show', 'id' => $model->id), array('class' => 'w3-ig w3-link-icon w3-border-1px-transparent w3-first w3-last ui-corner-all', 'title' => Yii::t('link', 'Show'))))); } $this->printJson($data); }
/** * @internal * * @return MArray */ protected function executeFaultRequest(MFaultRequest $request) { $failedFaults = new MMutableArray(); foreach ($request->faults()->toArray() as $fault) { $data = new MMutableDictionary(); $relationships = new MMutableDictionary(); $query = Sf("SELECT * FROM `%s` WHERE `objectID` = :objectID LIMIT 1", $fault->entity()->plural()); $id = $fault->objectID(); $statement = $this->connection()->prepare($query->stringValue()); $statement->bindParam(':objectID', $id, PDO::PARAM_INT); $statement->execute(); $row = $statement->fetch(PDO::FETCH_ASSOC); if ($row != null) { unset($row['objectID']); // Set the object's data foreach ($row as $key => $value) { $property = $fault->entity()->attributeWithName(S($key)); if ($property) { $boxedValue = null; if ($value != null) { if ($property->type() == MEntityDescriptionProperty::StringType) { $boxedValue = new MString($value); } else { if ($property->type() == MEntityDescriptionProperty::IntegerType) { $boxedValue = new MNumber($value); } else { if ($property->type() == MEntityDescriptionProperty::FloatType) { $boxedValue = new MNumber($value); } else { if ($property->type() == MEntityDescriptionProperty::BooleanType) { $boxedValue = new MNumber($value); } else { if ($property->type() == MEntityDescriptionProperty::DateType) { $boxedValue = MDate::parse($value); } else { if ($property->type() == MEntityDescriptionProperty::BinaryType) { $boxedValue = new MData($value); } } } } } } } $data->setObjectForKey(S($key), $boxedValue); } else { throw new MPersistentStoreException(S("Database structure incompatible with this model version!")); } } $fault->_setData($data); foreach ($fault->entity()->relationships()->toArray() as $relationship) { $relationshipQuery = Sf("SELECT * FROM `%s` WHERE `%s` = ?;", $relationship->tableName(), $relationship->columnName()); $objectID = $fault->objectID(); $statement = $this->connection()->prepare($relationshipQuery->stringValue()); $statement->bindParam(1, $objectID); $statement->execute(); $relationshipObjects = new MMutableArray(); foreach ($statement->fetchAll() as $relationshipRow) { $relationshipObject = $this->fetchObjectWithObjectID($this->persistentStoreCoordinator()->model()->entityWithName($relationship->type()), (int) $relationshipRow[$relationship->inverseColumnName()->stringValue()]); if ($relationshipObject) { $relationshipObjects->addObject($relationshipObject); } else { MLog("Warning: Object with ID [%s] is missing from the data store and could not be initialized!", $relationshipRow['objectID']); } } $relationships->setObjectForKey($relationship->name(), $relationshipObjects); } $fault->_setRelationships($relationships); } else { $failedFaults->addObject($fault); } } return $failedFaults; }
/** * Find all open tasks. * @param array of additional conditions * @return array of Task objects */ public function findAllOpenRecords($conditions = array()) { $id = isset($conditions[0]) && ctype_digit($conditions[0]) && $conditions[0] >= 1 ? $conditions[0] : null; $criteria = new CDbCriteria(); // close date is not set, or it is later than today $criteria->condition = "((`t`.`closeDate` IS NULL OR TO_DAYS('" . MDate::formatToDb(time(), 'date') . "') < TO_DAYS(`t`.`closeDate`)) AND `t`.`status`!='" . self::CANCELLED . "' AND `t`.`status`!='" . self::COMPLETED . "')"; if ($id) { $criteria->condition .= " OR `t`.`id` = '{$id}'"; } return self::model()->findAll($criteria); }
/** * Print out array of models for the jqGrid rows. */ public function actionGridData() { if (!Yii::app()->request->isPostRequest) { throw new CHttpException(400, Yii::t('http', 'Invalid request. Please do not repeat this request again.')); exit; } // specify request details $jqGrid = $this->processJqGridRequest(); // specify filter parameters $state = isset($_GET['state']) ? $_GET['state'] : null; if ($state !== 'all' && $state !== 'closed' && $state !== 'open') { $state = 'all'; } // criteria $criteria = new CDbCriteria(); $criteria->group = "`t`.`id`"; // required by together() $criteria->select = "`t`.contactName, `t`.createTime, `t`.deactivationTime, `t`.title, `t`.titleAbbr"; //$criteria->select="`t`.`contactName`, `t`.`createTime`, `t`.`deactivationTime`, `t`.`title`, `t`.`titleAbbr`"; // uncomment in yii-1.1.2 if ($jqGrid['searchField'] !== null && $jqGrid['searchString'] !== null && $jqGrid['searchOper'] !== null) { $field = array('contactName' => "`t`.`contactName`", 'createTime' => "`t`.`createTime`", 'deactivationTime' => "`t`.`deactivationTime`", 'title' => "`t`.`title`", 'titleAbbr' => "`t`.`titleAbbr`"); $operation = $this->getJqGridOperationArray(); $keywordFormula = $this->getJqGridKeywordFormulaArray(); if (isset($field[$jqGrid['searchField']]) && isset($operation[$jqGrid['searchOper']])) { $criteria->condition = '(' . $field[$jqGrid['searchField']] . ' ' . $operation[$jqGrid['searchOper']] . ' :keyword)'; $criteria->params = array(':keyword' => str_replace('keyword', $jqGrid['searchString'], $keywordFormula[$jqGrid['searchOper']])); // search by special field types if ($jqGrid['searchField'] === 'createTime' && ($keyword = strtotime($jqGrid['searchString'])) !== false) { $criteria->params = array(':keyword' => str_replace('keyword', $keyword, $keywordFormula[$jqGrid['searchOper']])); if (date('H:i:s', $keyword) === '00:00:00') { // visitor is looking for a precision by day, not by second $criteria->condition = '(TO_DAYS(FROM_UNIXTIME(' . $field[$jqGrid['searchField']] . ',"%Y-%m-%d")) ' . $operation[$jqGrid['searchOper']] . ' TO_DAYS(FROM_UNIXTIME(:keyword,"%Y-%m-%d")))'; } } } } if ($state === 'closed') { $criteria->addCondition("(`t`.`isActive` IS NULL OR `t`.`isActive`!=:isActive)"); $criteria->params[':isActive'] = Company::IS_ACTIVE; } else { if ($state === 'open') { $criteria->addCondition("`t`.`isActive`=:isActive"); $criteria->params[':isActive'] = Company::IS_ACTIVE; } } if (User::isClient()) { $criteria->addCondition("`Company_User2Company`.`userId`=:clientId AND `Company_User2Company`.`position`=:clientPosition"); $criteria->params[':clientId'] = Yii::app()->user->id; $criteria->params[':clientPosition'] = Company::OWNER; } // pagination $with = array(); if (strpos($criteria->condition, 'Company_User2Company') !== false) { $with[] = 'allUser2Company'; } if (count($with) >= 1) { $pages = new CPagination(Company::model()->with($with)->count($criteria)); } else { $pages = new CPagination(Company::model()->count($criteria)); } $pages->pageSize = $jqGrid['pageSize'] !== null ? $jqGrid['pageSize'] : self::GRID_PAGE_SIZE; $pages->applyLimit($criteria); // sort $sort = new CSort('Company'); $sort->attributes = array('contactName' => array('asc' => "`t`.`contactName`", 'desc' => "`t`.`contactName` desc", 'label' => Company::model()->getAttributeLabel('contactName')), 'createTime' => array('asc' => "`t`.`createTime`", 'desc' => "`t`.`createTime` desc", 'label' => Company::model()->getAttributeLabel('Opened')), 'deactivationTime' => array('asc' => "`t`.`deactivationTime`", 'desc' => "`t`.`deactivationTime` desc", 'label' => Company::model()->getAttributeLabel('Closed')), 'title' => array('asc' => "`t`.`title`", 'desc' => "`t`.`title` desc", 'label' => Company::model()->getAttributeLabel('title')), 'titleAbbr' => array('asc' => "`t`.`titleAbbr`", 'desc' => "`t`.`titleAbbr` desc", 'label' => Company::model()->getAttributeLabel('Abbr'))); $sort->defaultOrder = "`t`.`deactivationTime` ASC, `t`.`title` ASC"; $sort->applyOrder($criteria); // find all $with = array(); if (strpos($criteria->condition, 'Company_User2Company') !== false) { $with['allUser2Company'] = array('select' => 'id'); } $together = strpos($criteria->condition, 'Company_User2Company') !== false; if ($together) { $models = Company::model()->with($with)->together()->findAll($criteria); } else { $models = Company::model()->with($with)->findAll($criteria); } // create resulting data array $data = array('page' => $pages->getCurrentPage() + 1, 'total' => $pages->getPageCount(), 'records' => $pages->getItemCount(), 'rows' => array()); foreach ($models as $model) { $data['rows'][] = array('id' => $model->id, 'cell' => array(CHtml::encode($model->title), CHtml::encode($model->titleAbbr), CHtml::encode($model->contactName), CHtml::encode(MDate::format($model->createTime, 'medium', null)), CHtml::encode(MDate::format($model->deactivationTime, 'medium', null)), CHtml::link('<span class="ui-icon ui-icon-zoomin"></span>', array('show', 'id' => $model->id), array('class' => 'w3-ig w3-link-icon w3-border-1px-transparent w3-first ui-corner-all', 'title' => Yii::t('link', 'Show'))) . CHtml::link('<span class="ui-icon ui-icon-pencil"></span>', array('update', 'id' => $model->id), array('class' => 'w3-ig w3-link-icon w3-border-1px-transparent w3-last ui-corner-all', 'title' => Yii::t('link', 'Edit'))))); } $this->printJson($data); }
/** * Sets the object which represents the value for a certain attribute of this object * * Attributes are the properties and relationships of this object. This method sets * the object which represents the value of that attribute. * * You cannot use this method to set the value of a ToMany relationship, for that * you should use MManagedObject::addObjectToRelationship and * MManagedObject::removeObjectFromRelationship * * @see MManagedObject::addObjectToRelationship * @see MManagedObject::removeObjectFromRelationship * * @param MEntityDescriptionAttribute $attribute The attribute which you'd like to set * the value of * @param MObject $object The Object representing the value for that attribute * * @return void */ public function setObjectForAttribute(MEntityDescriptionAttribute $attribute, MObject $object = null) { $this->fireFault(); if ($attribute instanceof MEntityDescriptionProperty) { if ($object) { if ($attribute->type() == MEntityDescriptionProperty::StringType) { if (!$object instanceof MString) { throw new MInvalidManagedObjectOperationException($this, Sf("Invalid type [%s], expected [%s]!", str($object->className()), str(MString::className()))); } } else { if ($attribute->type() == MEntityDescriptionProperty::IntegerType) { if (!$object instanceof MNumber) { throw new MInvalidManagedObjectOperationException($this, Sf("Invalid type [%s], expected [%s]!", str($object->className()), str(MNumber::className()))); } } else { if ($attribute->type() == MEntityDescriptionProperty::FloatType) { if (!$object instanceof MNumber) { throw new MInvalidManagedObjectOperationException($this, Sf("Invalid type [%s], expected [%s]!", str($object->className()), str(MNumber::className()))); } } else { if ($attribute->type() == MEntityDescriptionProperty::BooleanType) { if (!$object instanceof MNumber) { throw new MInvalidManagedObjectOperationException($this, Sf("Invalid type [%s], expected [%s]!", str($object->className()), str(MNumber::className()))); } } else { if ($attribute->type() == MEntityDescriptionProperty::DateType) { if (!$object instanceof MDate) { throw new MInvalidManagedObjectOperationException($this, Sf("Invalid type [%s], expected [%s]!", str($object->className()), str(MDate::className()))); } } else { if ($attribute->type() == MEntityDescriptionProperty::BinaryType) { if (!$object instanceof MData) { throw new MInvalidManagedObjectOperationException($this, Sf("Invalid type [%s], expected [%s]!", str($object->className()), str(MData::className()))); } } else { throw new MInvalidManagedObjectOperationException($this, Sf("Unsupported type [%s]!", $attribute->type())); } } } } } } } $this->updatedData->setObjectForKey($attribute->name(), $object); } else { if ($attribute instanceof MEntityDescriptionRelationship) { if ($attribute->to() == MEntityDescriptionRelationship::ToMany) { throw new MInvalidManagedObjectOperationException($this, S("Could not set a ToMany relationship, please use add/remove")); } if (($oldArr = $this->relationships->objectForKey($attribute->name())) != null) { if ($oldArr->lastObject()) { $this->removeObjectFromRelationship($attribute, $oldArr->lastObject()); } } $this->addObjectToRelationship($attribute, $object); } else { throw new MManagedObjectException($this, S("Unknown attribute type!")); } } }
/** * * * @return MDate */ public function dateByAddingDate(MDate $date) { return new MDate($this->timestamp() + $date->timestamp()); }
public function __construct($datetime = NULL, $format = '') { parent::__construct($datetime, $format ?: Manager::getOptions('formatTimestamp')); }
/** * */ public function typeClassName() { if ($this->type() == MEntityDescriptionProperty::StringType) { return MString::className(); } else { if ($this->type() == MEntityDescriptionProperty::IntegerType) { return MNumber::className(); } else { if ($this->type() == MEntityDescriptionProperty::FloatType) { return MNumber::className(); } else { if ($this->type() == MEntityDescriptionProperty::BooleanType) { return MNumber::className(); } else { if ($this->type() == MEntityDescriptionProperty::DateType) { return MDate::className(); } else { if ($this->type() == MEntityDescriptionProperty::BinaryType) { return MData::className(); } else { return S(""); } } } } } } }
/** * @internal * * Used internally to parse the Model from it's model file * * @return void */ protected function parse() { $xmlModels = simplexml_load_file($this->modelFile()->path()->stringValue()); if (!$this->version()) { $this->version = S((string) $xmlModels->{'current-version'}); } $model = null; foreach ($xmlModels->model as $m) { if (S((string) $m['version'])->equals($this->version())) { $model = $m; } } if ($model != null) { $relationshipsToLink = new MMutableDictionary(); foreach ($model->entity as $entity) { $newEntity = new MEntityDescription(S((string) $entity['name']), S((string) $entity['plural']), S((string) $entity['class'])); foreach ($entity->property as $property) { $newProperty = new MEntityDescriptionProperty($newEntity, S((string) $property['name'])); if ((string) $property['type'] != null) { $newProperty->setType((string) $property['type']); } if ((string) $property['defaultValue'] != null) { $defaultValue = null; if ($newProperty->type() == MEntityDescriptionProperty::StringType) { $defaultValue = new MString((string) $property['defaultValue']); } else { if ($newProperty->type() == MEntityDescriptionProperty::IntegerType) { $defaultValue = MNumber::parseInt((string) $property['defaultValue']); } else { if ($newProperty->type() == MEntityDescriptionProperty::FloatType) { $defaultValue = MNumber::parseFloat((string) $property['defaultValue']); } else { if ($newProperty->type() == MEntityDescriptionProperty::BooleanType) { $defaultValue = MNumber::parseBool((string) $property['defaultValue']); } else { if ($newProperty->type() == MEntityDescriptionProperty::DateType) { $defaultValue = MDate::parseString((string) $property['defaultValue']); } else { if ($newProperty->type() == MEntityDescriptionProperty::BinaryType) { // BinaryType's defaultValue is ignored, always null } else { throw new MModelParseErrorException($this->modelFile(), Sf("Invalid data type '%s'", $newProperty->type())); } } } } } } $newProperty->setDefaultValue($defaultValue); } } foreach ($entity->relationship as $relationship) { $newRelationship = new MEntityDescriptionRelationship($newEntity, S((string) $relationship['name']), S((string) $relationship['type'])); $newRelationship->setSingular(S((string) $relationship['singular'])); if (strtolower((string) $relationship['to']) == "many") { $newRelationship->setTo(MEntityDescriptionRelationship::ToMany); } else { $newRelationship->setTo(MEntityDescriptionRelationship::ToOne); } if ($relationship['inverse'] != null) { $relationshipsToLink->setObjectForKey($newRelationship, S((string) $relationship['inverse'])); } } $this->addEntity($newEntity); } // Link relationships to their respective inverse relationships foreach ($relationshipsToLink->allKeys()->toArray() as $relationship) { $inverse = $relationshipsToLink->objectForKey($relationship); $inverseEntity = $this->entityWithName($relationship->type()); if ($inverseEntity) { $inverseRelationship = $inverseEntity->attributeWithName($inverse); if ($inverseRelationship) { $relationship->setInverseRelationship($inverseRelationship); } else { throw new MModelParseErrorException($this->modelFile(), Sf("Could not find the relationship named '%s' in entity '%s'", $inverse, $relationship->type())); } } else { throw new MModelParseErrorException($this->modelFile(), Sf("[%s->%s] Inverse relationship's entity named '%s' not defined in this model version", $relationship->entity()->name(), $relationship->name(), $relationship->type())); } } } else { throw new MModelVersionNotFoundException($this->modelFile()); } }
?> ui-widget-content ui-corner-all"> <?php echo CHtml::encode($model->getAttributeLabel('companyId')); ?> : <?php echo isset($model->company->id) ? CHtml::link(CHtml::encode($model->company->title), array('company/show', 'id' => $model->company->id)) : ''; ?> <br/> <?php echo CHtml::encode($model->getAttributeLabel('paymentDate')); ?> : <?php echo CHtml::encode(MDate::format($model->paymentDate, 'full', null)); ?> <br/> <?php echo CHtml::encode($model->getAttributeLabel('amount')); ?> : <?php echo CHtml::encode($model->amount); ?> <br/> <?php echo CHtml::encode($model->getAttributeLabel('paymentMethod')); ?> : <?php
/** * Print out array of models for the jqGrid rows. */ public function actionGridData() { if (!Yii::app()->request->isPostRequest) { throw new CHttpException(400, Yii::t('http', 'Invalid request. Please do not repeat this request again.')); exit; } // specify request details $jqGrid = $this->processJqGridRequest(); // specify filter parameters $accessType = isset($_GET['accessType']) ? $_GET['accessType'] : null; if ($accessType !== 'all' && $accessType !== (string) User::MEMBER && $accessType !== (string) User::CLIENT && $accessType !== (string) User::CONSULTANT && $accessType !== (string) User::MANAGER && $accessType !== (string) User::ADMINISTRATOR) { $accessType = 'all'; } $state = isset($_GET['state']) ? $_GET['state'] : null; if ($state !== 'all' && $state !== 'active' && $state !== 'inactive') { $state = 'all'; } // criteria $criteria = new CDbCriteria(); if ($jqGrid['searchField'] !== null && $jqGrid['searchString'] !== null && $jqGrid['searchOper'] !== null) { $field = array('accessType' => "`t`.`accessType`", 'createTime' => "`t`.`createTime`", 'email' => "`t`.`email`", 'screenName' => "`t`.`screenName`", 'deactivationTime' => "`User_UserDetails`.`deactivationTime`", 'occupation' => "`User_UserDetails`.`occupation`"); $operation = $this->getJqGridOperationArray(); $keywordFormula = $this->getJqGridKeywordFormulaArray(); if (isset($field[$jqGrid['searchField']]) && isset($operation[$jqGrid['searchOper']])) { $criteria->condition = '(' . $field[$jqGrid['searchField']] . ' ' . $operation[$jqGrid['searchOper']] . ' :keyword)'; $criteria->params = array(':keyword' => str_replace('keyword', $jqGrid['searchString'], $keywordFormula[$jqGrid['searchOper']])); // search by special field types if ($jqGrid['searchField'] === 'createTime' && ($keyword = strtotime($jqGrid['searchString'])) !== false) { $criteria->params = array(':keyword' => str_replace('keyword', $keyword, $keywordFormula[$jqGrid['searchOper']])); if (date('H:i:s', $keyword) === '00:00:00') { // visitor is looking for a precision by day, not by second $criteria->condition = '(TO_DAYS(FROM_UNIXTIME(' . $field[$jqGrid['searchField']] . ',"%Y-%m-%d")) ' . $operation[$jqGrid['searchOper']] . ' TO_DAYS(FROM_UNIXTIME(:keyword,"%Y-%m-%d")))'; } } } } if ($accessType === (string) User::MEMBER) { $criteria->addCondition("`t`.`accessType`=:member"); $criteria->params[':member'] = User::MEMBER; } else { if ($accessType === (string) User::CLIENT) { $criteria->addCondition("`t`.`accessType`=:client"); $criteria->params[':client'] = User::CLIENT; } else { if ($accessType === (string) User::CONSULTANT) { $criteria->addCondition("`t`.`accessType`=:consultant"); $criteria->params[':consultant'] = User::CONSULTANT; } else { if ($accessType === (string) User::MANAGER) { $criteria->addCondition("`t`.`accessType`=:manager"); $criteria->params[':manager'] = User::MANAGER; } else { if ($accessType === (string) User::ADMINISTRATOR) { $criteria->addCondition("`t`.`accessType`=:administrator"); $criteria->params[':administrator'] = User::ADMINISTRATOR; } } } } } if ($state === 'active') { $criteria->addCondition("(`t`.`isActive` IS NULL OR `t`.`isActive`!=:isNotActive)"); $criteria->params[':isNotActive'] = User::IS_NOT_ACTIVE; } else { if ($state === 'inactive') { $criteria->addCondition("`t`.`isActive`=:isNotActive"); $criteria->params[':isNotActive'] = User::IS_NOT_ACTIVE; } } // pagination $with = array(); if (strpos($criteria->condition, 'User_UserDetails') !== false) { $with[] = 'details'; } if (count($with) >= 1) { $pages = new CPagination(User::model()->with($with)->count($criteria)); } else { $pages = new CPagination(User::model()->count($criteria)); } $pages->pageSize = $jqGrid['pageSize'] !== null ? $jqGrid['pageSize'] : self::GRID_PAGE_SIZE; $pages->applyLimit($criteria); // sort $sort = new CSort('User'); $sort->attributes = array('accessType' => array('asc' => "`t`.`accessLevel`", 'desc' => "`t`.`accessLevel` desc", 'label' => User::model()->getAttributeLabel('accessType')), 'createTime' => array('asc' => "`t`.`createTime`", 'desc' => "`t`.`createTime` desc", 'label' => User::model()->getAttributeLabel('Registered')), 'email' => array('asc' => "`t`.`email`", 'desc' => "`t`.`email` desc", 'label' => User::model()->getAttributeLabel('email')), 'screenName' => array('asc' => "`t`.`screenName`", 'desc' => "`t`.`screenName` desc", 'label' => User::model()->getAttributeLabel('screenName')), 'deactivationTime' => array('asc' => "`User_UserDetails`.`deactivationTime`", 'desc' => "`User_UserDetails`.`deactivationTime` desc", 'label' => UserDetails::model()->getAttributeLabel('Deact')), 'occupation' => array('asc' => "`User_UserDetails`.`occupation`", 'desc' => "`User_UserDetails`.`occupation` desc", 'label' => UserDetails::model()->getAttributeLabel('occupation'))); $sort->defaultOrder = "`t`.`screenName`"; $sort->applyOrder($criteria); // find all $models = User::model()->with('details')->findAll($criteria); // create resulting data array $data = array('page' => $pages->getCurrentPage() + 1, 'total' => $pages->getPageCount(), 'records' => $pages->getItemCount(), 'rows' => array()); foreach ($models as $model) { $data['rows'][] = array('id' => $model->id, 'cell' => array(CHtml::encode($model->screenName), CHtml::encode($model->details->occupation), CHtml::encode($model->email), CHtml::encode(MDate::format($model->createTime, 'medium', null)), CHtml::encode(MDate::format($model->details->deactivationTime, 'medium', null)), CHtml::encode($model->getAttributeView('accessType')), CHtml::link('<span class="ui-icon ui-icon-zoomin"></span>', array('show', 'id' => $model->id), array('class' => 'w3-ig w3-link-icon w3-border-1px-transparent w3-first ui-corner-all', 'title' => Yii::t('link', 'Show'))) . CHtml::link('<span class="ui-icon ui-icon-pencil"></span>', array('update', 'id' => $model->id), array('class' => 'w3-ig w3-link-icon w3-border-1px-transparent w3-last ui-corner-all', 'title' => Yii::t('link', 'Edit'))))); } $this->printJson($data); }
echo CHtml::encode($model->getAttributeLabel('createTime')); ?> </div> <div class="w3-detail-row-value"><?php echo CHtml::encode(MDate::format($model->createTime, 'full')); ?> </div> <div class="clear"> </div> </div> <div class="w3-detail-row"> <div class="w3-detail-row-label"><?php echo CHtml::encode($model->getAttributeLabel('updateTime')); ?> </div> <div class="w3-detail-row-value"><?php echo CHtml::encode(MDate::format($model->updateTime, 'full')); ?> </div> <div class="clear"> </div> </div> <div class="w3-detail-row"> <div class="w3-detail-row-label"><?php echo CHtml::encode($model->getAttributeLabel('title')); ?> </div> <div class="w3-detail-row-value"><?php echo CHtml::encode($model->title); ?> </div> <div class="clear"> </div> </div>
public static function invertDate($date) { $mdate = new MDate($date); return $mdate->invert(); }
/** * Print out array of models for the jqGrid rows. */ public function actionGridData() { if (!Yii::app()->request->isPostRequest) { throw new CHttpException(400, Yii::t('http', 'Invalid request. Please do not repeat this request again.')); exit; } // specify request details $jqGrid = $this->processJqGridRequest(); // specify filter parameters $company = isset($_GET['company']) ? $_GET['company'] : null; if ($company !== 'all' && !ctype_digit($company)) { $company = 'all'; } $paymentMethod = isset($_GET['paymentMethod']) ? $_GET['paymentMethod'] : null; if ($paymentMethod !== 'all' && $paymentMethod !== (string) CompanyPayment::CASH && $paymentMethod !== (string) CompanyPayment::CHECK && $paymentMethod !== (string) CompanyPayment::CREDIT_CARD && $paymentMethod !== (string) CompanyPayment::PAYPAL && $paymentMethod !== (string) CompanyPayment::WIRE) { $paymentMethod = 'all'; } // criteria $criteria = new CDbCriteria(); $criteria->group = "`t`.`id`"; // required by together() $criteria->select = "`t`.amount, `t`.paymentDate, `t`.paymentMethod, `t`.paymentNumber"; //$criteria->select="`t`.`amount`, `t`.`paymentDate`, `t`.`paymentMethod`, `t`.`paymentNumber`"; // uncomment in yii-1.1.2 if ($jqGrid['searchField'] !== null && $jqGrid['searchString'] !== null && $jqGrid['searchOper'] !== null) { $field = array('amount' => "`t`.`amount`", 'paymentDate' => "`t`.`paymentDate`", 'paymentMethod' => "`t`.`paymentMethod`", 'paymentNumber' => "`t`.`paymentNumber`", 'company' => "`CompanyPayment_Company`.`title`"); $operation = $this->getJqGridOperationArray(); $keywordFormula = $this->getJqGridKeywordFormulaArray(); if (isset($field[$jqGrid['searchField']]) && isset($operation[$jqGrid['searchOper']])) { $criteria->condition = '(' . $field[$jqGrid['searchField']] . ' ' . $operation[$jqGrid['searchOper']] . ' :keyword)'; $criteria->params = array(':keyword' => str_replace('keyword', $jqGrid['searchString'], $keywordFormula[$jqGrid['searchOper']])); // search by special field types if ($jqGrid['searchField'] === 'createTime' && ($keyword = strtotime($jqGrid['searchString'])) !== false) { $criteria->params = array(':keyword' => str_replace('keyword', $keyword, $keywordFormula[$jqGrid['searchOper']])); if (date('H:i:s', $keyword) === '00:00:00') { // visitor is looking for a precision by day, not by second $criteria->condition = '(TO_DAYS(FROM_UNIXTIME(' . $field[$jqGrid['searchField']] . ',"%Y-%m-%d")) ' . $operation[$jqGrid['searchOper']] . ' TO_DAYS(FROM_UNIXTIME(:keyword,"%Y-%m-%d")))'; } } } } if ($company !== 'all') { $criteria->addCondition("`CompanyPayment_Company`.`id`=:companyId"); $criteria->params[':companyId'] = $company; } if ($paymentMethod === (string) CompanyPayment::CASH) { $criteria->addCondition("`t`.`paymentMethod`=:cash"); $criteria->params[':cash'] = CompanyPayment::CASH; } else { if ($paymentMethod === (string) CompanyPayment::CHECK) { $criteria->addCondition("`t`.`paymentMethod`=:check"); $criteria->params[':check'] = CompanyPayment::CHECK; } else { if ($paymentMethod === (string) CompanyPayment::CREDIT_CARD) { $criteria->addCondition("`t`.`paymentMethod`=:creditCard"); $criteria->params[':creditCard'] = CompanyPayment::CREDIT_CARD; } else { if ($paymentMethod === (string) CompanyPayment::PAYPAL) { $criteria->addCondition("`t`.`paymentMethod`=:paypal"); $criteria->params[':paypal'] = CompanyPayment::PAYPAL; } else { if ($paymentMethod === (string) CompanyPayment::WIRE) { $criteria->addCondition("`t`.`paymentMethod`=:wire"); $criteria->params[':wire'] = CompanyPayment::WIRE; } } } } } if (User::isClient()) { $criteria->addCondition("`Company_User2Company`.`userId`=:clientId AND `Company_User2Company`.`position`=:clientPosition"); $criteria->params[':clientId'] = Yii::app()->user->id; $criteria->params[':clientPosition'] = Company::OWNER; } // pagination $with = array(); if (strpos($criteria->condition, 'CompanyPayment_Company') !== false) { $with[] = 'company'; } if (strpos($criteria->condition, 'Company_User2Company') !== false) { $with[] = 'company.allUser2Company'; } if (count($with) >= 1) { $pages = new CPagination(CompanyPayment::model()->with($with)->count($criteria)); } else { $pages = new CPagination(CompanyPayment::model()->count($criteria)); } $pages->pageSize = $jqGrid['pageSize'] !== null ? $jqGrid['pageSize'] : self::GRID_PAGE_SIZE; $pages->applyLimit($criteria); // sort $sort = new CSort('CompanyPayment'); $sort->attributes = array('amount' => array('asc' => "`t`.`amount`", 'desc' => "`t`.`amount` desc", 'label' => CompanyPayment::model()->getAttributeLabel('amount')), 'paymentDate' => array('asc' => "`t`.`paymentDate`", 'desc' => "`t`.`paymentDate` desc", 'label' => CompanyPayment::model()->getAttributeLabel('Date')), 'paymentMethod' => array('asc' => "`t`.`paymentMethod`", 'desc' => "`t`.`paymentMethod` desc", 'label' => CompanyPayment::model()->getAttributeLabel('Method')), 'paymentNumber' => array('asc' => "`t`.`paymentNumber`", 'desc' => "`t`.`paymentNumber` desc", 'label' => CompanyPayment::model()->getAttributeLabel('Number')), 'company' => array('asc' => "`CompanyPayment_Company`.`title`", 'desc' => "`CompanyPayment_Company`.`title` desc", 'label' => CompanyPayment::model()->getAttributeLabel('companyId'))); $sort->defaultOrder = "`t`.`paymentDate` DESC"; $sort->applyOrder($criteria); // find all $with = array('company' => array('select' => 'title')); if (strpos($criteria->condition, 'Company_User2Company') !== false) { $with['company.allUser2Company'] = array('select' => 'id'); } $together = strpos($criteria->condition, 'Company_User2Company') !== false; if ($together) { $models = CompanyPayment::model()->with($with)->together()->findAll($criteria); } else { $models = CompanyPayment::model()->with($with)->findAll($criteria); } // create resulting data array $data = array('page' => $pages->getCurrentPage() + 1, 'total' => $pages->getPageCount(), 'records' => $pages->getItemCount(), 'rows' => array()); foreach ($models as $model) { $data['rows'][] = array('id' => $model->id, 'cell' => array(isset($model->company->id) ? CHtml::link(CHtml::encode($model->company->title), array('company/show', 'id' => $model->company->id)) : '', CHtml::encode(MDate::format($model->paymentDate, 'medium', null)), CHtml::encode($model->amount), CHtml::encode($model->getAttributeView('paymentMethod')), CHtml::encode($model->paymentNumber), CHtml::link('<span class="ui-icon ui-icon-zoomin"></span>', array('show', 'id' => $model->id), array('class' => 'w3-ig w3-link-icon w3-border-1px-transparent w3-first ui-corner-all', 'title' => Yii::t('link', 'Show'))) . CHtml::link('<span class="ui-icon ui-icon-pencil"></span>', array('update', 'id' => $model->id), array('class' => 'w3-ig w3-link-icon w3-border-1px-transparent w3-last ui-corner-all', 'title' => Yii::t('link', 'Edit'))))); } $this->printJson($data); }
?> </div> <div class="clear"> </div> </div> <?php } if ($model->isActive === User::IS_NOT_ACTIVE && !empty($model->details->deactivationTime) && ($model->isMe || Yii::app()->user->checkAccess(User::ADMINISTRATOR))) { // FIXME: decide/define by default (NULL) is active or not? - currently yes ?> <div class="w3-detail-row"> <div class="w3-detail-row-label"><?php echo CHtml::encode($model->details->getAttributeLabel('deactivationTime')); ?> </div> <div class="w3-detail-row-value"><?php echo CHtml::encode(MDate::format($model->details->deactivationTime, 'full')); ?> </div> <div class="clear"> </div> </div> <?php } if ($model->hasVirtualAttribute('id') && ($model->isMe || Yii::app()->user->checkAccess(User::ADMINISTRATOR))) { ?> <div class="w3-detail-row"> <div class="w3-detail-row-label"><?php echo CHtml::encode($model->getAttributeLabel('id')); ?> </div> <div class="w3-detail-row-value"><?php echo CHtml::encode($model->id);